package ru.jexp.rcp.supply.beans.ek;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;

import ru.jexp.izdelie.IEdinicaIzdelia;
import ru.jexp.izdelie.PostavkaMateriala;
import ru.jexp.izdelie.mestoizgotovlenia.IMestoIzgotovlenia;
import ru.jexp.rcp.supply.mui.JExpSupplyMessages;
import ru.jexp.rcp.supply.swtext.DecimalFormatter;
import ru.jexp.rcp.supply.swtext.EdizmerCombo;
import ru.jexp.rcp.supply.swtext.JExpCombo;
import ru.jexp.rcp.supply.swtext.JExpControlLookup;
import ru.jexp.rcp.supply.swtext.JExpDecimal;
import ru.jexp.rcp.supply.swtext.JExpDialogAdapter;
import ru.jexp.rcp.supply.swtext.factory.JExpControlFactory;
import ru.jexp.rcp.supply.swtext.factory.JExpDecorationFactory;
import ru.jexp.rcp.supply.swtext.factory.JExpLayoutFactory;
import ru.jexp.rcp.supply.swtext.factory.JExpLookupFactory;

public abstract class EkForm<EdinicaIzdeliaT extends IEdinicaIzdelia> extends JExpDialogAdapter implements EkFormPresenter.IView<EdinicaIzdeliaT>
{

	protected abstract JExpControlLookup<EdinicaIzdeliaT> createEdinicaIzdeliaLookup(Composite parent);
	
	private JExpControlLookup<EdinicaIzdeliaT> ek;
	private JExpDecimal edizmerValue;
	private EdizmerCombo edizmer;
	private JExpControlLookup<IMestoIzgotovlenia> pf;
	private JExpCombo<PostavkaMateriala> supply;

	public EkForm(Shell parentShell)
	{
		super(parentShell);
	}

	@Override
	protected void createControls(Composite parent)
	{
		parent.setLayout(new GridLayout(3, false));
		parent.setLayoutData(JExpLayoutFactory.gdFillBoth());
		ek = createEdinicaIzdeliaLookup(parent);
		JExpDecorationFactory.labelDecoration(ek.getLabel());
		ek.setLayoutData(JExpLayoutFactory.gdWithHorizontalSpanHorizontalSize(2, 200));
		JExpControlFactory.createLabel(parent, JExpSupplyMessages.Ek_addform_kolvo);
		edizmerValue = JExpControlFactory.createDecimal(parent, DecimalFormatter.EDIT_MASK_2);
		edizmerValue.setLayoutData(JExpLayoutFactory.gdWithSizeHorizontal(50));
		edizmer = EdizmerCombo.createAndFill(parent);
		pf = JExpLookupFactory.createPfLookup(parent, 200);
		pf.setLayoutData(JExpLayoutFactory.gdWithHorizontalSpanHorizontalSize(2, 200));
		JExpControlFactory.createLabel(parent, JExpSupplyMessages.Supply_field_name);
		supply = new JExpCombo<PostavkaMateriala>(parent, 185, PostavkaMateriala.class);
		supply.setLayoutData(JExpLayoutFactory.gdWithHorizontalSpanHorizontalSize(2, 200));
	}

	@Override
	public void createView()
	{
		create();
	}

	@Override
	public int openView()
	{
		return open();
	}

	@Override
	public JExpControlLookup<EdinicaIzdeliaT> getEk()
	{
		return ek;
	}

	@Override
	public JExpDecimal getEdizmerValue()
	{
		return edizmerValue;
	}

	@Override
	public EdizmerCombo getEdizmer()
	{
		return edizmer;
	}

	@Override
	public JExpControlLookup<IMestoIzgotovlenia> getPf()
	{
		return pf;
	}

	@Override
	public JExpCombo<PostavkaMateriala> getSupply()
	{
		return supply;
	}

}
